// require('./bootstrap');
// window.Vue = require('vue');
// window.VueRouter = require('vue-router');

import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index'
import router from '@/plugins/router'
import Antd from 'ant-design-vue'
import {Icon} from 'ant-design-vue'
import App from '@/views/App'
import 'ant-design-vue/dist/antd.css';
import {post,get,put,deletes,postfile,toJson,isEmpty,apiHandle} from '@/plugins/http.js' // 请求方式中间件
import {api} from '@/plugins/api' // 后端API
import {getSession,returnInfo,formatFloat} from '@/plugins/function' // 辅助方法
import VueLazyload from 'vue-lazyload' // 懒加载图片
import 'babel-polyfill' // 兼容IE
import VueAMap from 'vue-amap'


Vue.prototype.$api=api;
Vue.prototype.$post=post;
Vue.prototype.$get=get;
Vue.prototype.$put=put;
Vue.prototype.$delete=deletes;
Vue.prototype.$postfile=postfile;
Vue.prototype.$toJson=toJson;
Vue.prototype.$isEmpty=isEmpty;
Vue.prototype.$apiHandle=apiHandle;
Vue.prototype.$getSession=getSession; // 获取session
Vue.prototype.$returnInfo=returnInfo; // api返回信息做处理
Vue.prototype.$formatFloat=formatFloat; // 浮点型格式化

Vue.config.productionTip = false;

// 字体图标 iconFont
let fontjs = require('@/plugins/font');
const AFont = Icon.createFromIconfontCN({
    scriptUrl: fontjs,
});
Vue.use(Antd);
Vue.component('a-font', AFont);

Vue.use(VueLazyload); // 懒加载图片
Vue.use(VueAMap); // 引入vue-amap vue-amap是一套基于Vue 2.0和高德地图的地图组件。
VueAMap.initAMapApiLoader({
    // 高德的key
    key: 'f7619d49a4aea5cb76631ce884ea1817',
    // 插件集合
    // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
    plugin: ['AMap.Geolocation', 'AMap.ToolBar','AMap.Geocoder'],
    // 高德 sdk 版本，默认为 1.4.4
    // v: '1.4.4'
});

// 跳转页面回到顶部
router.afterEach(() => {
    window.scrollTo(0,0);
});

// 重复路由报错
const _vue_router_push = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    _vue_router_push
        .call(this, location)
        .catch(err => {
            if (err.name !== "NavigationDuplicated") {
                throw err;
            }
        })
}

Vue.use(VueRouter)

const app = new Vue({
    el: '#app',
    store,
    components: { App },
    router,
});
